//
//  TreeViewCell.m
//  DemoTree
//
//  Created by 尤维维 on 2017/11/10.
//  Copyright © 2017年 EmicNet. All rights reserved.
//

#import "TreeViewCell.h"
#import "TreeView.h"

@interface TreeViewCell()

@property(nonatomic, strong) TreeView *conView;

@end

@implementation TreeViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.conView = [[TreeView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 0) delegate:self.delegate];
        __weak TreeViewCell *weakSelf = self;
        self.conView.reloadBlock = ^{
            weakSelf.reloadBlock();
        };
        [self.contentView addSubview:self.conView];
    }
    return self;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier delegate:(id)delegate {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier] ) {
        self.delegate = delegate;
        self = [self initWithStyle:style reuseIdentifier:reuseIdentifier];
    }
    return self;
}

- (void)setModel:(TreeNodeModel *)model {
    _model = model;
    self.conView.model = model;
    CGRect frame = self.conView.frame;
    CGSize size = frame.size;
    size.height = [model height:[self.delegate tableViewCellHeight] headHeight:[self.delegate tableViewHeadHeight]];
    frame.size = size;
    self.conView.frame = frame;
}

- (void)setDelegate:(id)delegate {
    _delegate = delegate;
    self.conView.delegate = delegate;
}

- (void)setSelectContactArr:(NSMutableArray *)selectContactArr {
    _selectContactArr = selectContactArr;
    //    self.conView.selectContactArr = selectContactArr;
}

@end
